package com.common.help.test18;

import java.util.Arrays;

public class Test3 {

	
	public static void main(String[] args) {
		long starttime = System.nanoTime();
		long[] arr ={1535731200000l,1535904000000l,1536163200000l,1536249600000l,1536336000000l,1536508800000l,1536768000000l,1536854400000l,1536940800000l,1537113600000l,1537372800000l,1537459200000l,1537545600000l,1537804800000l,1537977600000l,1538064000000l,1538150400000l,1538928000000l,1539273600000l,1539532800000l,1539878400000l,1540137600000l,1540483200000l,1540742400000l};
		
		long start = 1536553555000l;
		long end = 1537244755000l;
		Arrays.sort(arr);
		int indexStart1 = Arrays.binarySearch(arr, start);
		System.out.println(indexStart1);
		boolean hasStart = false;
		boolean hasEnd = false;
		for(long aa : arr){
			if(aa==start){
				hasStart = true;
			}else if(aa==end){
				hasEnd = true;
			}
		}
		int ii = 0;
		if(hasStart&&hasEnd){
			ii = 0;
		}else{
			if(hasStart||hasEnd){
				ii = 1;
			}else{
				ii = 2;
			}
		}
		
		
		long[] arr2 = new long[arr.length+ii];
		for(int i=0;i<arr.length;i++){
			arr2[i] = arr[i];
		}
		if(ii==1){
			if(hasStart){
				arr2[arr2.length-1] = end;
			}else{
				arr2[arr2.length-1] = start;
			}
		}else if(ii==2){
			arr2[arr2.length-2] = start;
			arr2[arr2.length-1] = end;
		}
		
		Arrays.sort(arr2);
		
		int indexStart = Arrays.binarySearch(arr2, start);
		int indexEnd = Arrays.binarySearch(arr2, end);
		
		System.out.println("indexstart---"+indexStart);
		System.out.println("indexEnd---"+indexEnd);
		
		
		long[] data = Arrays.copyOfRange(arr2, indexStart, indexEnd+1);
		long endtime = System.nanoTime();
		System.out.println(endtime-starttime);
		for(long d : data){
			System.out.print(d+",");
		}
		
	}
	public static int test(int[] a, int fromIndex, int toIndex,int key){
		 int low = fromIndex;
	        int high = toIndex - 1;

	        while (low <= high) {
	            int mid = (low + high) >>> 1;
	            int midVal = a[mid];

	            if (midVal < key)
	                low = mid + 1;
	            else if (midVal > key)
	                high = mid - 1;
	            else
	                return mid; // key found
	        }
	        return -(low + 1);  // key not found.
	}
}
